//
//  LocationButtonView.m
//  BigToBig
//
//  Created by yi liu on 16/7/26.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "LocationButtonView.h"
#import "ShenqingRZViewController.h"

@interface LocationButtonView ()

//@property (nonatomic , strong)UIButton *locationButton;
@property (nonatomic , strong)UILabel *titleLabel;

@end

@implementation LocationButtonView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

+ (LocationButtonView *)createButtonViewWithFrame:(CGRect)frame Title:(NSString *)titleString ImageName:(NSString *)imageName{
    
    LocationButtonView *locationButtonView = [[LocationButtonView alloc]initWithFrame:frame];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width / 3 , frame.size.width / 3)];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.center = CGPointMake(frame.size.width / 2, frame.size.height / 3);
    [locationButtonView addSubview:imageView];
    
    locationButtonView.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, imageView.maxY + 10, frame.size.width, frame.size.height - imageView.maxY - 15)];
    locationButtonView.titleLabel.text = titleString;
    locationButtonView.titleLabel.textAlignment = NSTextAlignmentCenter;
    [locationButtonView addSubview:locationButtonView.titleLabel];
    
    UIButton *locationButton = [UIButton buttonWithType:UIButtonTypeSystem];
    locationButton.frame = CGRectMake(0, 0, locationButtonView.width, locationButtonView.height);
    [locationButton addTarget:locationButtonView action:@selector(locationButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [locationButtonView addSubview:locationButton];
    locationButtonView.layer.cornerRadius = 5;
    locationButtonView.layer.masksToBounds = YES;
    locationButtonView.layer.borderWidth = 2;
    locationButtonView.layer.borderColor = [COLOR_RGBA(235, 235, 235, 1) CGColor];

    return locationButtonView;
}

- (void)locationButtonAction:(UIButton *)button{
    [self.locationDelegate pushToDetailViewControllerWithTitle:self.titleLabel.text];
    
}



@end
